package com.example.wangzh.developkit.control;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
import androidx.core.app.ActivityCompat;
import androidx.viewpager.widget.ViewPager;

import com.example.wangzh.developkit.R;
import com.example.wangzh.developkit.adapter.GlideLoadAdapter;
import com.example.wangzh.developkit.base.BaseActivity;
import com.example.wangzh.developkit.widget.GalleryHandler;

import butterknife.BindView;
import me.phelps.library.PointIndicator;

/**
 * Created by wangzh on 2017/10/20.
 */

public class ShowPicActivity extends BaseActivity {
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    @BindView(R.id.pointIndicator)
    PointIndicator pointIndicator;

    static final int REQUESTCODE = 200;
    GalleryHandler galleryHandler;

    @Override
    protected int getLayout() {
        return R.layout.activity_show_pic;
    }

    @Override
    protected void initData() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                    != PackageManager.PERMISSION_GRANTED) {
                requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUESTCODE);
            }
        }
    }

    @Override
    protected void initView() {
        galleryHandler = new GalleryHandler(this, true);
        String[] imgUrls = new String[]{
                "http://img01.taopic.com/141025/234987-1410250J11189.jpg",
                "http://img0.imgtn.bdimg.com/it/u=3243486925,3348023943&fm=27&gp=0.jpg",
                "http://pic32.photophoto.cn/20140711/0011024086081224_b.jpg",
                "http://img1.3lian.com/2015/a1/84/d/102.jpg",
                "http://pic23.photophoto.cn/20120530/0020033092420808_b.jpg",
                "http://img1.3lian.com/2015/a1/95/d/105.jpg"};
        GlideLoadAdapter glideLoadAdapter = new GlideLoadAdapter(this,
                imgUrls, galleryHandler, R.drawable.blankness_small);
        viewPager.setAdapter(glideLoadAdapter);
        pointIndicator.setViewPager(viewPager);
        galleryHandler.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                viewPager.setCurrentItem(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

}
